package com.tanhua.server.controller;

import com.itheima.model.dto.RecommendUserDto;
import com.itheima.model.vo.NearUserVo;
import com.itheima.model.vo.PageResult;
import com.itheima.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaSevice tanhuaSevice;

    /**
     * 今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaSevice.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询分页推荐好友列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult pr = tanhuaSevice.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查看佳人详情
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity getLikeInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanhuaSevice.getLikeInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaSevice.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     *回复陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        //前端传递Integer类型的userId
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaSevice.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 左滑右滑-推荐用户列表
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardList() {
        List<TodayBest> list = this.tanhuaSevice.queryCardList();
        return ResponseEntity.ok(list);
    }

    /**
     * 右滑-喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity<Void> rightLove(@PathVariable ("id") Long userId){
        this.tanhuaSevice.rightLove(userId);
        return ResponseEntity.ok(null);

    }

    /**
     * 左滑-喜欢
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity<Void> leftLove(@PathVariable ("id") Long userId){
        this.tanhuaSevice.leftLove(userId);
        return ResponseEntity.ok(null);
    }
    /**
     *
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender , @RequestParam String distance){
       List<NearUserVo> list = this.tanhuaSevice.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }
}
